<?php
	include_once('dbcon.php');

	if (defined("ERRORS_LOG") == false) {

		define("ERRORS_LOG", 1);

		function logIfError($mysqli, $user_id, $file_name, $method_name, $location_code) {
			if ($mysqli->errno != 0) {
				$mysqli->query("INSERT INTO errors (errno, error, user_id, file, method, location_code, date_created) VALUES('".$mysqli->errno."', \"".$mysqli->error."\",'".$user_id."', '".$file_name."', '".$method_name."', '".$location_code."', '".date('Y-m-d H:i:s')."')");
			}
		}

		function logMsg($user_id, $msg) {
			global $mysqli;

			$mysqli->query("INSERT INTO log (user_id, activity, date) VALUES('".$user_id."','".$msg."','".date('Y-m-d H:i:s')."')");	
			logIfError($mysqli, $user_id, "error_log_db", "log", "1");
		}

		function logFlow($user_id, $from_content, $to_content, $extra) {
			global $mysqli;

			$mysqli->query("INSERT INTO users_flow (user_id, from_content, to_content, extra, date) VALUES('".$user_id."', '".$from_content."', '".$to_content."', '".$extra."', '".date('Y-m-d H:i:s')."')");	
			logIfError($mysqli, $user_id, "error_log_db", "logFlow", "1");
		}

	}
	
?>
